package com.skyolder.crutch;

import com.skyolder.crutch.ast.FileTree;
import com.skyolder.crutch.ast.Tree;
import com.skyolder.crutch.ast.builder.AstBuilder;
import com.skyolder.crutch.error.GrammarError;
import com.skyolder.crutch.error.RunError;
import com.skyolder.crutch.ev.Environment;
import com.skyolder.crutch.word.BufferTokenPiper;
import com.skyolder.crutch.word.FilterTokenPiper;
import com.skyolder.crutch.word.TokenQueue;
import com.skyolder.crutch.word.raw.BufferCharPiper;
import com.skyolder.crutch.word.raw.BufferCharQueue;
import com.skyolder.crutch.word.raw.CharPiper;
import com.skyolder.crutch.word.raw.CharReader;
import com.skyolder.crutch.word.raw.TokenPiper;

public class CrutchMan {
	Tree tree=null;
	Environment rootEnvironment;
	public CrutchMan(){
		rootEnvironment=new Environment(null);
	}
	public void build(CharReader charReader) throws GrammarError{
		TokenQueue tq=new TokenQueue(new BufferTokenPiper(new FilterTokenPiper(new TokenPiper(new BufferCharQueue(new BufferCharPiper(new CharPiper(charReader)))))));
		tree=AstBuilder.build(rootEnvironment, tq);
	}
	public void excute() throws RunError{
		tree.excute();
	}
	public void run(String functionName)throws RunError{
		FileTree ftree=(FileTree)tree;
		ftree.run(functionName);
	}
	public void register(String functionName,Object o){
		
	}
	public void putVar(String varName,Object v){
		
	}
	public Object getVar(String varName){
		return null;
	}
}
